package com.dz.risk.pojo.model;

import com.dz.risk.common.enums.CodeEnum;
import com.google.common.base.VerifyException;
import io.swagger.annotations.ApiModel;

/**
 * @author Doke
 * @version 1.0
 * @date 2021/01/21
 * json公共返回结果
 */
@ApiModel(description = "json公共返回结果实体")
public class CommonResult<E> {

    /**
     * 响应业务状态
     */
    private Integer code;
    /**
     * 响应消息
     */
    private String desc;

    /**
     * 响应中的数据
     */
    private Object data;


    public static CommonResult build(Integer status, String msg, Object data) {
        return new CommonResult(status, msg, data);
    }


    public static CommonResult ok(Object data) {
        return build(CodeEnum.SUCCESS.getCode(), CodeEnum.SUCCESS.getMsg(), data);
    }

    public static CommonResult ok() {
        return build(CodeEnum.SUCCESS.getCode(), CodeEnum.SUCCESS.getMsg(), null);
    }

    public static CommonResult fail() {
        return build(CodeEnum.FAIL.getCode(), CodeEnum.FAIL.getMsg());
    }

    public static CommonResult fail(String msg) {
        return build(CodeEnum.FAIL.getCode(), msg);
    }

    public static CommonResult fail(Integer status, String msg) {
        return build(status, msg);
    }

    public static CommonResult sysError(String msg) {
        return build(CodeEnum.SYSTEM_ERROR.getCode(), msg);
    }

    public static CommonResult sysError(Object data) {
        return build(CodeEnum.SYSTEM_ERROR.getCode(), CodeEnum.SYSTEM_ERROR.getMsg(), data);
    }

    public static void throwVerifyException(String msg) {
        throw new VerifyException(msg);
    }

    public CommonResult() {

    }

    public CommonResult(Integer code, String desc, Object data) {
        this.code = code;
        this.desc = desc;
        this.data = data;
    }

    public static CommonResult build(Integer status, String message) {
        return new CommonResult(status, message, null);
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}

